﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq.StockLinq;

namespace dhDataAcess.produceDAL.Stock
{
  public   class productStockDAL
    {
          string  tableName = "productStock";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public productStockDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入胚带库存表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productStockInsert(productStockModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
           // string insertstr = "insert into pbomMaster (mark,updateUser,updateDate,createUser,createDate,checkDate,spr,zbr,awgight,bweight,machineType,custNum,pname) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@checkDate,@spr,@zbr,@awgight,@bweight,@machineType,@custNum,@pname)";
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();

            SqlParameter[] para = {
                                    new SqlParameter ("@createDate",row .createDate ),
                                    new SqlParameter ("@createUser",row .createUser ),
                                    new SqlParameter ("@stockDateAccount",row .stockDateAccount ),
                                    new SqlParameter ("@stockQtyTakeoutma",row .stockQtyTakeoutma),
                                    new SqlParameter ("@stockQtyTakeoutM",row .stockQtyTakeoutM),
                                    new SqlParameter ("@stockQtyTakeoutL",row .stockQtyTakeoutL),
                                    new SqlParameter ("@stockQtyTakeoutKg",row .stockQtyTakeoutKg),
                                    new SqlParameter ("@stockQtyTakeinma",row.stockQtyTakeinma),
                                    new SqlParameter ("@stockQtyTakeinM",row .stockQtyTakeinM),
                                    new SqlParameter ("@stockQtyTakeinL",row .stockQtyTakeinL),
                                    new SqlParameter ("@stockQtyTakeinKg",row .stockQtyTakeinKg),
                                    new SqlParameter ("@stockQtyToutma",row .stockQtyToutma),
                                    new SqlParameter ("@stockQtyToutM",row .stockQtyToutM),
                                    new SqlParameter ("@stockQtyToutL",row .stockQtyToutL),
                                    new SqlParameter ("@stockQtyToutKg",row .stockQtyToutKg),
                                    new SqlParameter ("@stockQtyTinma",row .stockQtyTinma),
                                    new SqlParameter ("@stockQtyTinM",row .stockQtyTinM),
                                    new SqlParameter ("@stockQtyTinL",row .stockQtyTinL),
                                    new SqlParameter ("@stockQtyTinKg",row .stockQtyTinKg),
                                    new SqlParameter ("@stockOutma",row .stockOutma),
                                    new SqlParameter ("@stockOutM",row .stockOutM),
                                    new SqlParameter ("@stockOutL",row .stockOutL),
                                    new SqlParameter ("@stockOutKg",row .stockOutKg),
                                    new SqlParameter ("@stockInma",row .stockInma),
                                    new SqlParameter ("@stockInM",row .stockInM),
                                    new SqlParameter ("@stockInL",row .stockInM),
                                    new SqlParameter ("@stockInKg",row .stockInM),
                                    new SqlParameter ("@stockQtyQcma",row .stockInM),
                                    new SqlParameter ("@stockQtyQcM",row .stockQtyQcM),
                                    new SqlParameter ("@stockQtyQcL",row .stockQtyQcL),
                                    new SqlParameter ("@stockQtyQcKg",row .stockQtyQcKg),
                                    new SqlParameter ("@stockQtyma",row .stockQtyma),
                                    new SqlParameter ("@stockQtyM",row .stockQtyM),
                                    new SqlParameter ("@stockQtyL",row .stockQtyL),
                                    new SqlParameter ("@stockQtyKg",row .stockQtyKg),
                                    new SqlParameter ("@pname",row .pname ),
                                    new SqlParameter ("@stockName",row .stockName )
                                };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新胚带库存表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productStockUpdate(productStockModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                    new SqlParameter ("@createDate",row .createDate ),
                                    new SqlParameter ("@createUser",row .createUser ),
                                    new SqlParameter ("@stockDateAccount",row .stockDateAccount ),
                                    new SqlParameter ("@stockQtyTakeoutma",row .stockQtyTakeoutma),
                                    new SqlParameter ("@stockQtyTakeoutM",row .stockQtyTakeoutM),
                                    new SqlParameter ("@stockQtyTakeoutL",row .stockQtyTakeoutL),
                                    new SqlParameter ("@stockQtyTakeoutKg",row .stockQtyTakeoutKg),
                                    new SqlParameter ("@stockQtyTakeinma",row.stockQtyTakeinma),
                                    new SqlParameter ("@stockQtyTakeinM",row .stockQtyTakeinM),
                                    new SqlParameter ("@stockQtyTakeinL",row .stockQtyTakeinL),
                                    new SqlParameter ("@stockQtyTakeinKg",row .stockQtyTakeinKg),
                                    new SqlParameter ("@stockQtyToutma",row .stockQtyToutma),
                                    new SqlParameter ("@stockQtyToutM",row .stockQtyToutM),
                                    new SqlParameter ("@stockQtyToutL",row .stockQtyToutL),
                                    new SqlParameter ("@stockQtyToutKg",row .stockQtyToutKg),
                                    new SqlParameter ("@stockQtyTinma",row .stockQtyTinma),
                                    new SqlParameter ("@stockQtyTinM",row .stockQtyTinM),
                                    new SqlParameter ("@stockQtyTinL",row .stockQtyTinL),
                                    new SqlParameter ("@stockQtyTinKg",row .stockQtyTinKg),
                                    new SqlParameter ("@stockOutma",row .stockOutma),
                                    new SqlParameter ("@stockOutM",row .stockOutM),
                                    new SqlParameter ("@stockOutL",row .stockOutL),
                                    new SqlParameter ("@stockOutKg",row .stockOutKg),
                                    new SqlParameter ("@stockInma",row .stockInma),
                                    new SqlParameter ("@stockInM",row .stockInM),
                                    new SqlParameter ("@stockInL",row .stockInM),
                                    new SqlParameter ("@stockInKg",row .stockInM),
                                    new SqlParameter ("@stockQtyQcma",row .stockInM),
                                    new SqlParameter ("@stockQtyQcM",row .stockQtyQcM),
                                    new SqlParameter ("@stockQtyQcL",row .stockQtyQcL),
                                    new SqlParameter ("@stockQtyQcKg",row .stockQtyQcKg),
                                    new SqlParameter ("@stockQtyma",row .stockQtyma),
                                    new SqlParameter ("@stockQtyM",row .stockQtyM),
                                    new SqlParameter ("@stockQtyL",row .stockQtyL),
                                    new SqlParameter ("@stockQtyKg",row .stockQtyKg),
                                    new SqlParameter ("@pname",row .pname ),
                                    new SqlParameter ("@stockName",row .stockName )
                                };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行胚带库存表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productStockDel(string recordID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@recordID",recordID )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
